package com.leetcode.sorts.back_track;

import java.util.*;

/**
 * @Author: WuPeng
 * @Date: 2021/6/10 5:31 下午
 *
 * 77.组合
 *
 */
public class Combination_77 {
    List<List<Integer>> result = new ArrayList<>();
    Deque<Integer> path = new LinkedList<>();

    public List<List<Integer>> combination(int n, int k){
        backTrack(n, k, 1);
        return result;
    }

    private void backTrack(int n, int k, int start){
        if (path.size() == k){
            result.add(new ArrayList<>(path));
            return;
        }
        for (int i=start; i<=n; i++) {
            path.offerLast(i);
            backTrack(n, k, i+1);
            path.pollLast();
        }
    }

    public static void main(String[] args) {
        Combination_77 combination = new Combination_77();
        List<List<Integer>> result = combination.combination(4, 2);
        System.out.println(Arrays.toString(result.toArray()));

    }


}
